package C_Paper;

import java.util.*;

public class C100_7 {
    //分配土地
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[][] x = new int[m][n];
        Map<Integer, List<Integer[]>> map = new HashMap<>();
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                x[i][j] = sc.nextInt();
                if (x[i][j] != 0) {
                    List<Integer[]> list = map.get(x[i][j]);
                    if (list == null) list = new ArrayList<>();
                    list.add(new Integer[]{i,j});
                    map.put(x[i][j],list);
                }
            }
        }
        int min = n*m;
        for (Map.Entry<Integer, List<Integer[]>> entry : map.entrySet()) {
            List<Integer[]> list = entry.getValue();
//            if (list.size() < 2) continue;
            int xm = m;
            int ym = n;
            int xx = 0;
            int yx = 0;
            for (Integer[] i : list) {
                xm = Math.min(xm,i[0]);
                ym = Math.min(ym,i[1]);
                xx = Math.max(xx,i[0]);
                yx = Math.max(yx,i[1]);
            }
            min = Math.min(min,(yx - ym + 1) * (xx - xm + 1));
        }
        System.out.println(min);
    }
}
